
var FFEntry = Class.create({
  initialize: function(entry){
	if(entry=='undefined' || entry==undefined) return;
	this.entry = entry;
	this.id = entry.id;
	this.url = entry.url;
	this.date = entry.date;
	this.body = entry.body;
	this.from = new FFEntryFrom(entry.from);
	this.to = this.setArray(entry.to);
	this.comments = this.setArray(entry.comments);	
	this.likes = this.setArray(entry.likes);
	this.thumbnails = this.setArray(entry.thumbnails);
	this.files = this.setArray(entry.files);
	this.via = new FFEntryVia(entry.via);
	this.geo = new FFEntryGeo(entry.geo);
	this.commands = entry.commands;
	
	//EXTRA PROPERTIES
	this.numberOfFrom = this.from.length;
	this.numberOfTo = this.to.length;
	this.numberOfComments = this.comments.length;
	this.numberOfLikes = this.likes.length;
	this.numberOfThumbnails = this.thumbnails.length;
	this.numberOfFiles = this.files.length;
  },
  
  getID: function(){
	return this.id;  
  },
  
  getUrl: function(){
	return this.url;
  },  
  
  getDate: function(){
	return this.date;
  },
  
  getBody: function(){
	return this.body;
  },
  
  getFrom: function(){
	return this.from;
  },
  
  getTo: function(){
	return this.to;
  },
  
  getComments: function(){
	return this.comments;
  },
  
  getLikes: function(){
	return this.likes;
  },
   
  getThumbnails: function(){
	return this.thumbnails;
  },
  
  getFiles: function(){
	return this.files;
  },
  
  getVia: function(){
	return this.via;
  },
  
  getGeo: function(){
	return this.geo;
  },
  
  getCommands: function(){
	return this.commands;
  },
  
  //EXTRE METHODS
  
  getNumberOfFrom: function(){
	return this.numberOfFrom;  
  },
  
  getNumbersOfTo: function(){
	return this.numbersOfTo;  
  },
  
  getNumberOfComments: function(){
	return this.numberOfComments;  
  },
  
  getNumberOfLikes: function(){
	return this.numberOfLikes;  
  },
  
  getNumberOfThumbnails: function(){
    return this.numberOfThumbnails;  
  },
  
  getNumberOfFiles: function(){
	return this.numberOfFiles;  
  },
  
  getComment: function(k){
	  if(this.comments<=0)
		  return null;
	  else{
		  var c = this.comments[k];
		  return FFEntryComment(c);
	  }
  },
  
  toString: function(isHtml){
    var newLine = "\n";
	if(isHtml) newLine = '<br/>';
	var feedToString = ''; 
	feedToString += 'id: ' + this.id + newLine;
	feedToString += 'url: ' + this.url + newLine;
	feedToString += 'date: ' + this.date + newLine;
	feedToString += 'body: ' + this.body + newLine;
	feedToString += 'from: ' + newLine + this.from.toString(true);// + newLine;
	feedToString += 'to: ' + this.player + newLine;
	
	feedToString += 'comments: ' + this.comments.length + newLine;
	for(var c = 0; c<this.getNumberOfComments(); c++){
		feedToString += "-- comment " + c + newLine;
		var element = new FFEntryComment(this.comments.pop(c));
		feedToString += element.toString(true);
	}
	
	feedToString += 'likes: ' + (this.likes.length) + newLine;
	for(var l = 0; l<this.getNumberOfLikes(); l++){
		feedToString += "-- likes " + l + newLine;
		var element = new FFEntryLike(this.likes.pop(l));
		feedToString += element.toString(true);
	}
	
	feedToString += 'thumbnails: ' + this.thumbnails.length + newLine;
	for(var t = 0; t<this.getNumberOfThumbnails(); t++){
		feedToString += "-- thumbnails " + t + newLine;
		var element = new FFEntryThumbnail(this.thumbnails.pop(t));
		feedToString += element.toString(true);
	}
	
	feedToString += 'file: ' + this.files.length + newLine;
	for(var f = 0; c<this.getFiles(); f++){
		feedToString += "-- file " + f + newLine;
		var element = new FFEntryFiles(this.files.pop(f));
		feedToString += newLine + element.toString(true);
	}
	
	feedToString += 'via: ' + newLine + this.via.toString(true) + newLine;
	feedToString += 'geo: ' + newLine + this.geo.toString(true) + newLine;
	feedToString += 'commands: ' + this.commands + newLine;
	feedToString += newLine;
	return feedToString;  
  },
  
  isUndefined: function(object){
	 return (object=='undefined' || object==undefined);  
  },
  
  setArray: function(object){
	if(this.isUndefined(object))
	  return new Array(0);
	else
	  return object;	
  }
});



var FFEntryThumbnail = Class.create({
  initialize: function(thumbnail){
	this.thumbnail = thumbnail;
	this.url = thumbnail.url;
	this.link = thumbnail.link;
	this.width = thumbnail.width;
	this.heigth = thumbnail.heigth;
	this.player = thumbnail.player;
  },
  
  getUrl: function(){
	return this.url;
  },
  
  getLink: function(){
	return this.link;
  },
  
  getWidth: function(){
	return this.width;
  },
  
  getHeight: function(){
	return this.height;
  },
  
  getPlayer: function(){
	return this.player;
  },
  
  //EXTRA METHODs
  
  toString: function(isHtml){
	var newLine = "\n";
	if(isHtml) newLine = '<br/>';
	var feedToString = '';  
	feedToString += 'url: ' + this.url + newLine;
	feedToString += 'link: ' + this.link + newLine;
	feedToString += 'width: ' + this.width + newLine;
	feedToString += 'heigth: ' + this.heigth + newLine;
	feedToString += 'player: ' + this.player + newLine;
	return feedToString;
  }
});


var FFEntryFile = Class.create({
  initialize: function(file){
	this.file = file;
	this.url = file.url;
	this.type = file.url;
	this.name = file.name;
	this.icon = file.icon;
	this.size = file.size;
  },
  
  getUrl: function(){
	return this.url;
  },
  
  getType: function(){
	return this.type;  
  },
  
  getName: function(){
	return this.name;
  },
  
  getIcon: function(){
	return this.icon;
  },
  
  getSize: function(){
	return this.size;
  },
  
  //EXTRA METHODs
  
  toString: function(isHtml){
	var newLine = "\n";
	if(isHtml) newLine = '<br/>';
	var feedToString = '';  
	feedToString += 'url: ' + this.url + newLine;
	feedToString += 'type: ' + this.type + newLine;
	feedToString += 'name: ' + this.name + newLine;
	feedToString += 'icon: ' + this.icon + newLine;
	feedToString += 'size: ' + this.size + newLine;
	return feedToString;
  }
});


var FFEntryVia = Class.create({
  initialize: function(via){
	if(via==undefined || via=='undefined') return;
	this.via = via; 
	this.name = via.name;
	this.url = via.url;
  },
  
  getName: function(){
	return this.name;
  },
  
  getUrl: function(){
	return this.url;
  },	
    
  //EXTRA METHODs
  
  getIcon: function(){
	var iconName = this.getName();
	var path = 'res/img/';
	var icon = new Element('img');
	if(iconName!=null){
	  iconName = iconName.toLowerCase();	
	  if(iconName.indexOf('google')!=-1){
		icon.src = path + 'google_16.png';
	  }else if (iconName.indexOf('bookmarklet')!=-1){
		icon.src = path + 'friendfeed_16.png';  
	  }else if (iconName.indexOf('twitter')!=-1){
		icon.src = path + 'twitter_16.png';
	  }else if (iconName.indexOf('facebook')!=-1){
		icon.src = path + 'facebook_16.png';  
	  }else if (iconName.indexOf('last.fm')!=-1){
		icon.src = path + 'lastfm_16.png';  
	  }else if (iconName.indexOf('blogger')!=-1){
		icon.src = path + 'blogger_16.png';  
	  }else if (iconName.indexOf('aim')!=-1){
		icon.src = path + 'aim_16.png';  
	  }else if (iconName.indexOf('apple')!=-1){
		icon.src = path + 'apple_16.png';  
	  }else if (iconName.indexOf('bebo')!=-1){
		icon.src = path + 'bebo_16.png';
	  }else if (iconName.indexOf('brightkite')!=-1){
		icon.src = path + 'brightkite_16.png'; 
	  }else if (iconName.indexOf('delicious')!=-1){
		icon.src = path + 'delicious_16.png';  
	  }else if (iconName.indexOf('digg')!=-1){
		icon.src = path + 'digg_16.png';  
	  }else if (iconName.indexOf('dopplr')!=-1){
		icon.src = path + 'dopplr_16.png';  
	  }else if (iconName.indexOf('email')!=-1){
		icon.src = path + 'email_16.png';   
	  }else if (iconName.indexOf('flickr')!=-1){
			icon.src = path + 'flickr_16.png';   
	  }else{
		icon.src = path + 'rss_16.png';
	  }
	}else{
	  icon.src = path + 'rss_16.png';
	}	
	return icon;
  },
  
  toString: function(isHtml){
	var newLine = "\n";
	if(isHtml) newLine = '<br/>';
	var feedToString = '';  
	feedToString += 'name: ' + this.name + newLine;
	feedToString += 'url: ' + this.url;
	return feedToString;
  }
}); 


var FFEntryGeo = Class.create({
  initialize: function(geo){
	if(geo==undefined || geo=='undefined') return;
	this.geo = geo; 
	this.lat = geo.lat;
	this.long = geo.long;
  },
	  
  getLat: function(){
	return this.lat;
  },
	  
  getLong: function(){
	return this.long;
  },

  //EXTRA METHODs
  
  toString: function(isHtml){
	var newLine = "\n";
	if(isHtml) newLine = '<br/>';
	var feedToString = '';  
	feedToString += 'lat: ' + this.lat + newLine;
	feedToString += 'long: ' + this.long;
	return feedToString;
  }
});


var FFEntryComment = Class.create({
  initialize: function(comment){
	if(comment=='undefined' || comment==undefined) return;
	this.comment = comment;
	this.id = comment.id;
	this.date = comment.date;
	this.body = comment.body;
	this.from = new FFEntryFrom(comment.from);
	this.via = comment.via;
	this.commands = comment.commands;
  },	
  
  getId: function(){
	return this.id;  
  },
  
  getDate: function(){
	return this.date;  
  }, 
  
  getBody: function(){
	return this.body;  
  }, 
  
  getFrom:function(){
	return this.from; 
  },
  
  getVia: function(){
	return this.via;  
  },
  
  getCommands: function(){
	return this.commands;  
  },

  //EXTRA METHODs
  
  toString: function(isHtml){
	var newLine = "\n";
	if(isHtml) newLine = '<br/>';
	var feedToString = '';
	feedToString += 'id: ' + this.id + newLine;
	feedToString += 'date: ' + this.date + newLine;
	feedToString += 'body: ' + this.body + newLine;
	feedToString += 'from: ' + newLine + this.from.toString(true);// + newLine;
	feedToString += 'via: ' + this.via + newLine;
	feedToString += 'commands: ' + this.commands + newLine;
	return feedToString;
  }
});

var FFEntryLike = Class.create({
  initialize: function(like){
	this.like = like;
	this.date = like.date;
	this.from = new FFEntryFrom(like.from);
  },
  
  getDate: function(){
	return this.date;
  },
  
  getFrom: function(){
	return this.from;
  },

  //EXTRA METHODs
  
  toString: function(isHtml){
	var newLine = "\n";
	if(isHtml) newLine = '<br/>';
	var feedToString = '';  
	feedToString += 'date: ' + this.date + newLine;
	feedToString += 'from: ' + newLine + this.from.toString(true);
	return feedToString;
  } 
  
});

var FFEntryFrom = Class.create({
  initialize: function(from){
	this.from = from;
	this.id = from.id;
	this.name = from.name;
	this.description = from.description;
	this.type = from.type;
	this.isPrivate = from.private;
	this.commands = from.commands;
  },
  
  getId: function(){
	return this.id;
  },
  
  getName: function(){
	return this.name;
  },
  
  getDescription: function(){
	 return this.description; 
  },

  getType: function(){
	return this.type;
  },
  
  isPrivate: function(){
	return this.isPrivate;  
  },
  
  getCommands: function(){
	return this.commands;  
  },


  //EXTRA METHODs
  
  toString: function(isHtml){
	var newLine = "\n";
	if(isHtml) newLine = '<br/>';
	var feedToString = '';  
	feedToString += 'id: ' + this.id + newLine;
	feedToString += 'name: ' + this.name + newLine;
	feedToString += 'description: ' + this.description + newLine;
	feedToString += 'type: ' + this.type + newLine;
	feedToString += 'private: ' + this.isPrivate + newLine;
	feedToString += 'commands: ' + this.commands + newLine;
	return feedToString;
  } 
  
});




